package com.haste.system.controller;

import com.haste.common.domain.vo.ResponseVo;
import com.haste.common.service.IBaseMenuService;
import com.haste.system.domain.vo.MenuVo;
import com.haste.system.service.IMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 16554
 */
@RestController
@RequestMapping("/menu")
@Api(tags = {"菜单管理"})
public class MenuController {

    @Resource
    private IBaseMenuService baseMenuService;

    @Resource
    private IMenuService menuService;

    @PostMapping("/insert")
    @ApiOperation(value = "新增菜单")
    public ResponseVo insert(@RequestBody MenuVo menuVo){
        menuService.save(menuVo);
        return new ResponseVo<>().ok();
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改菜单")
    public ResponseVo update(@RequestBody MenuVo menuVo){
        menuService.updateById(menuVo);
        return new ResponseVo<>().ok();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除菜单")
    public ResponseVo delete(@PathVariable String id){
        menuService.removeById(id);
        return new ResponseVo<>().ok();
    }

    @PutMapping("/update/tidyUp")
    @ApiOperation(value = "一键整理")
    public ResponseVo tidyUp(){
        menuService.tidyUp();
        return new ResponseVo<>().ok();
    }

    @PostMapping("/list")
    @ApiOperation(value = "查询菜单")
    public ResponseVo<List<MenuVo>> list(){
        List<MenuVo> list = menuService.list();
        return new ResponseVo().ok(list);
    }
}
